﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using weikebuluo.DAL;
using weikebuluo.Common;
using weikebuluo.Model;

namespace weikeweixin.web.admin.vip
{
    public partial class cardset : weikeweixin.web.admin.cs.adminbase
    {
        v_cardset_dal cardsetdal = new v_cardset_dal();
        v_cardset_model cardsetmodel = new v_cardset_model();
        public string cardset_name = "会员卡名称";
        public string cardset_bgpic = "http://school.wechat007.com/web/admin/all/images/0618587298.png";
        public string cardset_namecolor = "#FFFFFF";
        public string cardset_codecolor = "#FFFFFF";
        public string Url = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Url = Request.Url.Authority + "/web/wechat/vip/index.aspx";
            DataTable dtcardset = cardsetdal.GetList("user_id="+user_id).Tables[0];
            if (dtcardset.Rows.Count > 0) {
                cardset_name = dtcardset.Rows[0]["cardset_name"].ToString();
                cardset_bgpic = dtcardset.Rows[0]["cardset_bgpic"].ToString();
                cardset_namecolor = dtcardset.Rows[0]["cardset_namecolor"].ToString();
                cardset_codecolor = dtcardset.Rows[0]["cardset_codecolor"].ToString();
            }
            switch (Request.Form["action"])
            {
                case "bindcardconfig":
                    submint();
                    break;
            }

        }

        private void submint() {
            DataTable dtcardset = cardsetdal.GetList("user_id=" + user_id).Tables[0];
            if (dtcardset.Rows.Count > 0) {
                cardsetmodel = cardsetdal.GetModel(int.Parse(dtcardset.Rows[0]["cardset_id"].ToString()));
            }
            cardsetmodel.cardset_name = Request.Form["cardset_name"];
            cardsetmodel.cardset_bgpic = Request.Form["cardset_bgpic"];
            cardsetmodel.cardset_namecolor = Request.Form["cardset_namecolor"];
            cardsetmodel.cardset_codecolor = Request.Form["cardset_codecolor"];
            cardsetmodel.user_id = int.Parse(user_id);
                 
            if (dtcardset.Rows.Count > 0)
            {
                cardsetdal.Update(cardsetmodel);
                Response.Write("{\"errno\":\"0\",\"tip\":\"会员修改成功！\",\"url\":\"cardset.aspx\",\"error\":\"\"}");
                Response.End();
            }
            else {
                cardsetdal.Add(cardsetmodel);
                Response.Write("{\"errno\":\"0\",\"tip\":\"会员设置成功！\",\"url\":\"cardset.aspx\",\"error\":\"\"}");
                Response.End();
            }
            
        }
    }
}